from google.appengine.api import users
from google.appengine.ext import webapp

providers = {
    'Google':'gmail.com',
    'Yahoo':'yahoo.com',
    'Facebook':'facebook.com'
}

class HandleUser(webapp.RequestHandler):
    """Callback Handler."""
    def get(self):
        user = users.get_current_user()
        if user: #signed already
            data = {
                'username':user.nickname(),
                'logout_url':user.create_logout_url(self.request.uri)
            }
            ## TODO Check why are you trying to get the path
            path = os.path.join(os.path.dirname(__file__), 'index.html')
            self.response.out.write(template.render(path, 
                                                    template_values))
        else:
            ## TODO Check why are you trying to get the path
            path = os.path.join(os.path.dirname(__file__), 'index.html')
            self.response.out.write(template.render(path, 
                                                    providers))

        """GET request handler.
        Called when authorisation is granted by the user.
        Generates access_token, an OAuthHmacToken object.
        From this we can retrieve both the token and token_secret
        for a user.
        The object is saved using AeSave().
        """
        """
        current_uid = users.get_current_user().user_id()
        client = gdata.client.GDClient()
        saved_request_token = gdata.gauth.AeLoad(current_uid)
        request_token = gdata.gauth.AuthorizeRequestToken(
        saved_request_token, self.request.uri)
        access_token = client.GetAccessToken(request_token)
        gdata.gauth.AeSave(
        access_token, users.get_current_user().user_id())
        self.redirect('/'
        """

